#include "Delay.h"
#include <reg52.h>
#define GPIO_KEY P1
/**
 * @brief  矩阵键盘读取按键键码
 * @param  无
 * @retval KeyNumber 按下按键的键码值
 */
char getkey() {
  char a;
  char keyvalue;
  GPIO_KEY = 0x0f;
  while (1) {
    if (GPIO_KEY != 0x0f) {
      Delay(20);
      if (GPIO_KEY != 0x0f) {
        switch (GPIO_KEY) {
        case (0x07):
          keyvalue = 1;
          break;
        case (0x0b):
          keyvalue = 2;
          break;
        case (0x0d):
          keyvalue = 3;
          break;
        case (0x0e):
          keyvalue = 4;
          break;
        }
        GPIO_KEY = 0xf0;
        switch (GPIO_KEY) {
        case (0x70):
          break;
        case (0xb0):
          keyvalue += 4;
          break;
        case (0xd0):
          keyvalue += 8;
          break;
        case (0xe0):
          keyvalue += 12;
          break;
        }
        break;
      }
    }
  }
  while ((a < 50) && (GPIO_KEY != 0xf0)) // 松手检测
  {
    Delay(100);
    a++;
  }
  return keyvalue;
}
